<template>
  <div>
    <BasicTable @register="registerTable">
      <template #toolbar>
        <a-button type="primary" v-auth="'system:app:update'" @click="handleCreate">
          新增
        </a-button>
      </template>
      <template #action="{ record }">
        <TableAction
          :actions="[
            {
              icon: 'clarity:note-edit-line',
              onClick: handleUpdate.bind(null, record),
              auth: 'system:app:update',
            },
            {
              icon: 'ant-design:delete-outlined',
              color: 'error',
              auth: 'system:app:delete',
              popConfirm: {
                title: '是否确认删除',
                confirm: handleDelete.bind(null, record.id),
              },
            },
          ]"
        />
      </template>
    </BasicTable>
    <AppDrawer @register="registerDrawer" @success="reload" />
  </div>
</template>
<script lang="ts">
  import { defineComponent } from 'vue';

  import { BasicTable, useTable, TableAction } from '/@/components/Table';

  import { useExtendDrawer } from '/@/components/Drawer';
  import AppDrawer from './AppDrawer.vue';

  import { columns, searchFormSchema } from './app.data';
  import { pageList, deleteById } from './app.api';

  export default defineComponent({
    name: 'AppManagement',
    components: { BasicTable, TableAction, AppDrawer },
    setup() {
      const [registerTable, { reload }] = useTable({
        title: '系统应用列表',
        api: pageList,
        columns,
        formConfig: {
          labelWidth: 120,
          schemas: searchFormSchema,
        },
        useSearchForm: true,
        showTableSetting: true,
        bordered: true,
        showIndexColumn: false,
        actionColumn: {
          width: 80,
          title: '操作',
          dataIndex: 'action',
          slots: { customRender: 'action' },
          fixed: undefined,
        },
      });

      const extendAction = useExtendDrawer(reload, { deleteApi: deleteById });

      return {
        registerTable,
        reload,
        ...extendAction,
      };
    },
  });
</script>
